package servlet;

import hbase.HbaseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author:xuyuanhong
 * @Date:Created in 2022/3/13 10:07
 */

@WebServlet(name = "ServletCPut",urlPatterns = "/HbaseServletCPut")
public class ServletCPut extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String tname = request.getParameter("tablename");
        String id = request.getParameter("id");
        String familyName = request.getParameter("familyname");
        String qualifier = request.getParameter("qualifier");
        String data = request.getParameter("data");
        String msg = "-";
//        if (s)!!!!!!!!!!!!!!!!!!!dui
        if (qualifier.equals("Name")) {
            try {

                if (HbaseUtil.putC(tname, id, familyName, qualifier, data)) {
                    msg = "success";
                } else {
                    msg = "error";
                }
            }catch(Exception e){
                e.printStackTrace();
            }
        }else{
            msg = "输入信息不可改";

        }
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println(msg);
        out.flush();
        out.close();
    }
}
